package com.aitaoxue.palx.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import de.greenrobot.dao.AbstractDaoMaster;
import de.greenrobot.dao.AbstractDaoSession;
import de.greenrobot.dao.identityscope.IdentityScopeType;

public class RongyunDaoMaster extends AbstractDaoMaster {

	public static final int SCHEMA_VERSION = 3;

	public static void createAllTables(SQLiteDatabase db, boolean ifNotExists) {
		UserInfosDAO.createTable(db, ifNotExists);
	}

	public static void dropAllTables(SQLiteDatabase db, boolean ifExists) {
		UserInfosDAO.dropTable(db, ifExists);
	}

	public static class RongyunOpenHelper extends SQLiteOpenHelper {

		public RongyunOpenHelper(Context context, String name,
				CursorFactory factory) {
			super(context, name, factory, SCHEMA_VERSION);
			System.out.println("here");
		}

		@Override
		public void onCreate(SQLiteDatabase db) {
			createAllTables(db, false);
		}

		@Override
		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			dropAllTables(db, true);
			onCreate(db);
		}
	}

	public RongyunDaoMaster(SQLiteDatabase db) {
		super(db, SCHEMA_VERSION);

		try {
			registerDaoClass(UserInfosDAO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	@Override
	public RongyunDaoSession newSession() {
		return new RongyunDaoSession(db, IdentityScopeType.Session,
				daoConfigMap);
	}

	@Override
	public AbstractDaoSession newSession(IdentityScopeType type) {
		return new RongyunDaoSession(db, type, daoConfigMap);
	}

}
